package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;
    @Autowired
    private RoomInfoMapper roomInfoMapper;
    @Autowired
    private LeaseTermMapper leaseTermMapper;
    @Autowired
    private PaymentTypeMapper paymentTypeMapper;
    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;
    /**
     * @author gengjian
     * @date 2024/12/12 15:29:35
     * 根据id查询租约vo(签约公寓，房间，租期，支付方式)
     */
    @Override
    public AgreementVo getAgreementVoById(Long id) {
        //根据租约id获取租约信息
        LeaseAgreement leaseAgreement = super.getById(id);
        //根据租约信息获取签约公寓id 通过id获取公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());
        //根据租约信息获取房间id，通过id获取房间信息
        RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());
        //根据租约信息获取租期id，通过id获取租期信息
        LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());
        //根据租约信息获取支付方式id，通过id获取支付方式信息
        PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());
        //封装到租期vo中
        AgreementVo agreementVo = new AgreementVo();
        agreementVo.setLeaseTerm(leaseTerm);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        //cp 租期信息
        BeanUtils.copyProperties(leaseAgreement,agreementVo);
        return agreementVo;
    }

    /**
     * @author gengjian
     * @date 2024/12/12 16:00:30
     * 分页动态条件查询租约vo
     */
    @Override
    public void PageAgreementVoByQuery(IPage<AgreementVo> page, AgreementQueryVo queryVo) {
        leaseAgreementMapper.pageAgreementVoByQuery(page,queryVo);
    }
}




